package com.jackrain.nea.omslocal.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jackrain.nea.web.query.QueryEngine;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Discription: 发货视图数据状态修改
 * Created with IntelliJ IDEA.
 * @Author cs
 * @Date 2017/12/14 13:41
 */
@Component
@Slf4j
public class ChangelogsticsStatusService {

    /**
     * 修改同步数据状态为 9,   0未同步, 1  同步成功 , 2 同步失败 , 9 已发送
     *
     * @param jsonArray
     */
    public void changeStatus1(JSONArray jsonArray) {


        // synstatus = 9 时,该发货信息已经发送,未收到线上回执
        String sql = "update T_OMS_OrderOutStorage set syncstatus = 9, SyncTime = ? where id = ? ";
        JSONArray paramArr = new JSONArray();
        try {

            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject tempObj = JSONObject.parseObject(jsonArray.get(i).toString());
                int id = tempObj.getIntValue("ID");
                QueryEngine.getInstance().executeUpdate(sql, new Object[]{new Date(System.currentTimeMillis()),id});
            }

        } catch (Exception e) {
            // 修改库存状态失败
            log.error(e.getMessage());
        }

    }


    /**
     * 修改同步数据状态为同步成功 1
     * @param jsonArray
     */
    public void changeStatus2(JSONArray jsonArray) {


        // synstatus = 2 时,该库存信息已经发送
        String sql = "update T_OMS_OrderOutStorage set syncstatus = 1 where id = ? ";
        JSONArray paramArr = new JSONArray();
        try {

            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject tempObj = JSONObject.parseObject(jsonArray.get(i).toString());
                int id = tempObj.getIntValue("ID");
                QueryEngine.getInstance().executeUpdate(sql, new Object[]{id});
            }

        } catch (Exception e) {
            // 修改库存状态失败
            log.error(e.getMessage());
        }

    }


}
